<template>
  <div class="main-content" style="width:80%">
    <el-card>
    <p class="front-title">寄养订单信息</p>
    <div class="front-table">
      <div class="search">
        <el-input  class="search-input"  v-model="search.searchContent" placeholder="请输入宠物名" suffix-icon="el-icon-search"></el-input>
        <el-button type="primary" class="search-button"  plain @click="loadData()">搜索</el-button>
        <el-button type="warning"  plain @click="reset()">重置</el-button>
      </div>
      <el-table
          :header-cell-style="{'text-align':'center'}"
          :cell-style="{'text-align':'center'}"
          :data="tableData"
          style="width: 100%">
        <el-table-column prop="id" label="ID" width="50"></el-table-column>
        <el-table-column prop="petName" label="宠物名" > </el-table-column>
        <el-table-column prop="merchantName" label="店铺名"> </el-table-column>
        <el-table-column prop="owner" label="寄养人" ></el-table-column>
        <el-table-column prop="state" label="状态">
          <template slot-scope="scope">
            <el-tag type="success"> {{scope.row.state}}</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="owner" label="主人"> </el-table-column>
        <el-table-column prop="" label="操作" width="160">
          <template slot-scope="scope">
            <el-button type="primary"  icon="el-icon-view" @click="see(scope.row)"></el-button>
            <el-button type="primary"  icon="el-icon-s-comment"></el-button>
          </template>
        </el-table-column>

      </el-table>
      <el-dialog title="寄养订单" :visible.sync="dialogFormVisible" width="40%">
        <el-form :model="form" label-position="right" label-width="100px" style="padding-right: 40px">
          <el-form-item label="宠物名字">
            <el-input  v-model="form.petName" disabled></el-input>
          </el-form-item>
          <el-form-item label="寄养人">
            <el-input  v-model="form.owner" disabled></el-input>
          </el-form-item>
          <el-form-item label="开始时间" >
            <el-input  v-model="form.startDate" readonly></el-input>
          </el-form-item>
          <el-form-item label="结束时间" >
            <el-input  v-model="form.endDate" readonly></el-input>
          </el-form-item>
          <el-form-item label="订单时间" >
            <el-input  v-model="form.time" readonly></el-input>
          </el-form-item>
          <el-form-item label="备注" >
            <el-input  v-model="form.remark" readonly></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button  @click="dialogFormVisible = false">取 消</el-button>
        </div>
      </el-dialog>
    </div>
    <div  style="margin-top: 20px">
      <el-pagination
          background
          @current-change="handleCurrentChange"
          :current-page="pageNum"
          :page-sizes="[5, 10, 20]"
          :page-size="pageSize"
          layout="total, prev, pager, next"
          :total="total">
      </el-pagination>
    </div>

    </el-card>
  </div>
</template>

<script>

import request from "@/utils/request";


export default {
  data() {
    return {
      search:{},
      user: JSON.parse(localStorage.getItem('userInfo') || '{}'),
      form:{},
      dialogFormVisible:false,
      pageNum:1,
      pageSize:6,
      total:0,
    }
  },
  mounted() {
    this.loadData()
  },
  // methods：本页面所有的点击事件或者其他函数定义区
  methods: {
    loadData(){
      request.get("/fosterOrder/selectPage",{
        params:{
          pageNum:this.pageNum,
          pageSize:this.pageSize,
          userId:this.user.id,
          petName:this.search.searchContent
        }
      }).then(res=>{
        if (res.code==='0'){
          console.log(res.data)
          this.tableData=res.data.list
          this.total=res.data.total
        }

      })
    },
    handleCurrentChange(pageNum) {
      this.pageNum = pageNum;
      this.loadData()
    },
    reset(){
      this.search.searchContent = null
      this.loadData()
    },
    save() {
      if (!this.form.id) {
        //新增 为空
        request.post("fosterOrder/save", this.form).then(res => {
          if (res.code === '0') {
            this.$message.success('保存成功');
            this.loadData()
            this.dialogFormVisible = false
          }
        })
      } else {
        request.post("fosterOrder/update", this.form).then(res => {
          if (res.code === '0') {
            this.$message.success('修改成功');
            this.loadData()
            this.dialogFormVisible = false
          }

        })
      }
    },
    del(id){
      this.$confirm('您确定删除吗？', '确认删除', {type: "warning"}).then(response => {
        request.delete('/fosterOrder/delete/' + id).then(res => {
          if (res.code === '0') {   // 表示操作成功
            this.$message.success('操作成功')
            this.loadData()
          } else {
            this.$message.error(res.msg)  // 弹出错误的信息
          }
        })
      })
          .catch(()=>{})
    },
    see(row){
      this.$set(this.form,'selectDate',[row.startDate,row.endDate])
      this.form=row
      this.dialogFormVisible=true
    },
    handleAvatarSuccess(response) {
      // 获取后台传来的图片路径
      this.form.pic = response.data
      this.$forceUpdate()
    },
  }
}
</script>
<style>

</style>